


####################################################
# GETCOAUTHNETWK.R
#
# This function construct a network from the
# author data set.
#
#This function computes 
#
# Arguments:
#   startyear               
#   endyear               
#
######################################################

library(igraph)
library(foreign)

getnetwork <- function(startyear,endyear,data=NULL,y=NULL) {

  if (is.null(data)) data<-read.csv("networkdatac.csv",header=TRUE)
  if (is.null(y)) y<-subset(data, year>=startyear & year<(endyear+1)) 

  n1<-max(data$auth1+1)
  g1<-graph.empty(n1,directed=FALSE)
  
  a<-subset(y, nauthors==2)  
  g1<-add.edges(g1,rbind(a$auth1,a$auth2))

  a2<-subset(y, nauthors==3)
  g1<-add.edges(g1,rbind(a2$auth1,a2$auth2))
  g1<-add.edges(g1,rbind(a2$auth1,a2$auth3))
  g1<-add.edges(g1,rbind(a2$auth2,a2$auth3))

  simplify(g1)
}
